<template>
	<view class="pd pt60 pm120">
		<view class="formrow">
			<view class="z9 fz28">
				名称
			</view>
			<view class="mt20 pr">
				<input type="text" value="" placeholder="请输名称" class="jhhgerttyt" v-model="cardetail.name"/>
			</view>
		</view>

	
		<view class="formrow mt70" @tap="carInputClick">
			<view class="z9 fz28">
				车牌号
			</view>
			<view class="mt20 pr jhhgerttyt row">
			
				<view class="col ml30 fz40 cf">
					{{cardetail.license_full}}
				</view>
			</view>				
		</view>
		<plate-number ref="plate" v-model="cardetail.license_full" @showOrHide="showOrHide"></plate-number>
	<!-- 	<view class="formrow mt70">
			<view class="z9 fz28">
				车型
			</view>
			<view class="mt20 pr jhhgerttyt row">
				<view class="col">					
					<picker @change="bindPickerChange" :value="index" :range="array">
						{{cardetail.model}}
					</picker>
				</view>
				<uni-icons type="right" color="#fff" size="16" class="mr10"></uni-icons>
			</view>
		</view> -->
		<view class="formrow mt70">
			<view class="z9 fz28">
				车型
			</view>
			<navigator url='/pages/AddVhicle/index' class="mt20 pr jhhgerttyt row">
				<view class="col">
				<!-- <text class="z9 ">请选择地区</text> -->
				<text v-if="carbrand.brands">
						{{carbrand.brands}}-{{carbrand.model}}-{{carbrand.series}}
				</text>	
				<text class="z9 " v-else>
					请选择车型
				</text>
				</view>
				<!-- <uni-icons type="right" color="#fff" size="16" class="mr10"></uni-icons> -->
				<uni-icons type="right" color="#fff" size="16" class="mr10"></uni-icons>
			</navigator>
		</view>
		<view class="formrow mt70">
			<view class="z9 fz28">
				产品序列号
			</view>
			<view class="mt20 pr jhhgerttyt eeertsewer">
				{{cardetail.serial}}
			</view>
		</view>

		<view class="formrow mt40">
			<view class="z9 fz28">
				车架号
			</view>
			<view class="mt20 pr  ">
				<input type="text" value="1G1BL52P7TR115520" class="jhhgerttyt" v-model="cardetail.vin"/>
			</view>
		</view>

		<view class="formrow mt40">
			<view class="z9 fz28">
				发动机号
			</view>
			<view class="mt20 pr  ">
				<input type="text" value="1G1BL52P7TR115520" class="jhhgerttyt" v-model="cardetail.engine" />
			</view>
		</view>

		<view class="formrow mt70">
			<view class="z9 fz28">
				出厂年份
			</view>
			<view class="mt20 pr jhhgerttyt row z9  ">
				<picker mode="date" @change="jjcerta" class=" w100">
					<text v-if="from.jhhgdfc">{{from.jhhgdfc}}</text>
					<text v-else class="z9">出厂年份 </text>
					<image src="../../static/img/AddViceKey/kjjhfb.png" class="drrtsert ab" mode="widthFix"></image>
				</picker>

			</view>
		</view>

	</view>
</template>
<script>
	import plateNumber from '@/components/plate-number/plateNumber.vue'
	export default {
		data() {
			return {
				index:0,
				indexs:0,
				province:['京','冀','晋','蒙','辽','吉','黑','沪','苏','浙','皖','闽','赣','鲁','豫','鄂','湘','粤','桂','琼','渝','川','黔','滇'],
				array:['新宝骏-新宝骏RS-3-2020款','新宝骏-新宝骏RS-3-2020款2','新宝骏-新宝骏RS-3-2020款3'],
				from: {
					jhhgdfc: ''
				},
				cardetail:"",
				carid:"",
				carbrand:{
					brands:'',
					model:'',
					series:''
				}
			}
		},
		components: {plateNumber},
		onNavigationBarButtonTap() {
			this.modify()
		},
		onLoad(options) {
			console.log("传来",options.carid)
			this.carid=options.carid
			this.cdetail(options.carid)
			uni.$on('carbrand',(params)=>{
			        if(params.type == 1){
						this.carbrand.brands =  params.name
					}else if(params.type == 2){
						this.carbrand.series =  params.name
					}else{
						this.carbrand.model =  params.name
					}
					this.cardetail.model = this.carbrand.brands+this.carbrand.series+this.carbrand.model
			    
			    console.log(this.cardetail.model);
			    console.log(this.carbrand);
				})
		},
		onUnload(){
			uni.$off('carbrand')
		},
		methods: {
			carInputClick() {
			    this.$refs.plate.show();
			},
			jjcerta(e) {
				this.from.jhhgdfc = e.detail.value
			},
			bindPickerChange(e){
				this.index = e.detail.value
				this.cardetail.model=this.array[ e.detail.value]
			},
			bindPickerChangeProvince(e){
				this.indexs = e.detail.value
				this.cardetail.license_head=this.province[e.detail.value]
			},
			async cdetail(id){
				let details=await this.get('/api/car/'+id)
				console.log("得到的车辆详情",details)	
				this.cardetail=details.data
				this.from.jhhgdfc=details.data.year
				this.carbrand.brands = this.cardetail.model
			},
			async modify(){				
				var car=this.cardetail
				let params={}
				params.license_head=car.license_head
				params.license_full=car.license_full
				params.model=car.model
				params.name=car.name
				if(car.vin.length >0 ){
					params.vin=car.vin
				}
				if(car.engine.length >0 ){
					params.engine=car.engine
				}
				if(car.year.length >0 ){
					params.year=car.year
				}
				let minfo=await this.get('/api/car/'+this.carid,params,'PUT')
				console.log("修改信息",minfo)
				if(minfo.code==0){
					uni.showToast({
						title:"修改成功"
					})
					setTimeout(function(){
						uni.navigateBack({
							delta: 1
						})
					},2000)
				}
			}
		},
		mounted() {}
	}
</script>
<style scoped>
	
</style>
